#ifndef GAMETD_ENEMY_H
#define GAMETD_ENEMY_H

#include <functional>
#include "Timer.h"
#include "Router.h"
#include "Vector2.h"
#include "Animation.h"
#include "ResourcesManager.h"

class Enemy {
public:
    typedef std::function<void(Enemy *enemy)> SkillCallback;

public:
    Enemy();
    ~Enemy() = default;

    void OnUpdate(double delta);
    void OnRender(SDL_Renderer *renderer);
    void SetOnSkillReleased(SkillCallback on_skill_released);
    void IncreaseHp(double val);
    void DecreaseHp(double val);
    void SlowDown();
    void SetPosition(const Vector2 &position);
    void SetRouter(const Router *rout);
    void MakeInvalid();
    double GetHp() const;
    const Vector2 &GetSize() const;
    const Vector2 &GetPosition() const;
    const Vector2 &GetVelocity() const;
    double GetDamage() const;
    double GetRewardRatio() const;
    double GetRecoverRadius() const;
    double GetRecoverIntensity() const;
    bool CanRemove() const;
    double GetRouterProcess() const; // 敌人到达目的地的进度
    void SetEnemyAttribute(ResID resId, ResID sketchResId);

private:
    void RefreshPositionTarget();

protected:
    Vector2 size;       // 敌人的尺寸大小

    Timer timerSkill;   // 释放技能的定时器

    // 敌人上下左右的运动动画
    Animation anim_up;
    Animation anim_down;
    Animation anim_left;
    Animation anim_right;
    Animation anim_up_sketch;
    Animation anim_down_sketch;
    Animation anim_left_sketch;
    Animation anim_right_sketch;

    double hp = 0;
    double maxHp = 0;
    double speed = 0;
    double maxSpeed = 0;
    double damage = 0;
    double rewardRatio = 0;
    double recoverInterval = 0;
    double recoverRange = 0;
    double recoverIntensity = 0;

private:
    Vector2 position;            // 位置
    Vector2 velocity;            // 速度
    Vector2 direction;           // 方向
    bool isValid = true;         // 有没有被击杀
    Timer timerSketch;           // 剪影效果
    bool isShowSketch = false;

    Animation *animCurrent = nullptr;       // 当前的动画
    SkillCallback onSkillReleased;          // 技能释放的回调函数
    Timer timerRestoreSpeed;                // 回复速度的定时器
    const Router *router = nullptr;         // 当前是哪个路径
    int idxTarget = 0;                      // 当前走到哪个单元格
    Vector2 positionTarget;                 // 目标位置
};

#endif // GAMETD_ENEMY_H
